#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : bigDataProject 
@File    : order_api.py
@IDE     : PyCharm 
@Author  : Mario
@Date    : 2022/11/11 18:23 
@Describe: 订单相关接口
"""
from typing import Text

from api.pos_api.base_pos_api import BasePosAPI
from utils.common.common_control import get_json_result


class OrderAPI(BasePosAPI):

    def order_submit(self, submit_data: Text):
        """
        提交堂食订单
        :param submit_data: 下单数据
        :return:
        """
        payload = submit_data
        response = self.http_request('order/submit', payload, "POS提交堂食订单")
        return response

    def order_detail(self, order_no: Text):
        """
        台位订单详情
        :param order_no:订单号
        :return:
        """
        payload = '{"orderNo":"' + order_no + '"}'
        response = self.http_request('order/detail', payload, "POS台位订单详情")
        return response

    def get_vip_info(self, card_no: Text):
        """
        获取会员详细信息
        :param card_no: 会员号
        :return:
        """
        payload = '{"cardNo":"' + card_no + '"}'
        response = self.http_request('order/vip/input', payload, "POS获取会员详细信息")
        return response

    def vip_bind(self, card_no: Text, order_no: Text):
        """
        订单绑定会员
        :param card_no: 会员号
        :param order_no: 订单号
        :return:
        """
        vip_info = self.get_vip_info(card_no)
        customer_id = get_json_result(vip_info, '$..customerId')
        payload = '{"cardNo":"' + card_no + '","customerId":"' + str(customer_id) + '","orderNo":"' + order_no + '"}'
        response = self.http_request('order/vip/bind', payload, "POS订单绑定会员")
        return response

    def order_summary_list(self, start_time, end_time, page_num='1', page_size='100', business_type='1',
                           order_status='1'):
        """
        订单列表查询
        :param start_time: 开始时间
        :param end_time: 结束时间
        :param page_num: 第几页，默认1
        :param page_size: 每页展示几条，默认100
        :param business_type: 订单类型 1:堂食 2:外卖
        :param order_status: 0:未结、1:已结、2:未退、3:已退
        :return:
        """
        payload = '{"endTime":"' + end_time + '","startTime":"' + start_time + '","businessType":"' + business_type + \
                  '","pageNum":"' + page_num + '","pageSize":"' + page_size + '","orderStatus":"' + order_status + '"}'
        response = self.http_request('order/summary/list', payload, "POS订单列表查询")
        return response

    def order_summary_canteen_detail(self, order_no: Text, customer_id: Text):
        """
        堂食正向订单详情
        :param order_no:	订单号
        :param customer_id: 会员id
        :return:
        """
        payload = '{"orderNo":"' + order_no + '","customerId":"' + customer_id + '"}'
        response = self.http_request('order/summary/canteen/detail', payload, "POS堂食正向订单详情")
        return response

    def order_summary_canteen_refund_detail(self, order_no: Text, customer_id: Text = '1000350379'):
        """
        堂食逆向订单详情
        :param order_no: 订单号
        :param customer_id: 会员id
        :return:
        """
        payload = '{"orderNo":"' + order_no + '","customerId":"' + customer_id + '"}'
        response = self.http_request('order/summary/canteen/refund-detail', payload, "POS堂食逆向订单详情")
        return response

    def pos_work_detail(self, start_date: Text, end_date: Text, work_type='3', business_type='1'):
        """
        员工交班记录详情
        :param start_date: 开始时间
        :param end_date: 结束时间
        :param work_type: 类型: 1、单班次交班表 2、POS机号汇总表 3、日汇总 4、门店销售汇总表
        :param business_type: 业务类型： 1、堂食,2、外卖, 不传查询全部
        :return:
        """
        payload = '{"startDate":"' + start_date + '","endDate":"' + end_date + '","type":"' + work_type + \
                  '","businessType":"' + business_type + '"}'
        response = self.http_request('pos/work/detail', payload, "POS员工交班记录详情")
        return response


if __name__ == '__main__':
    test = OrderAPI('823882', 'sit')
    order_detail = test.pos_work_detail(start_date='2022-11-14 00:00:00', end_date='2022-11-14 23:59:59')
